package com.dailyblue.project.estate.commons.handler;

import com.dailyblue.project.estate.commons.util.JsonResult;
import com.dailyblue.project.estate.commons.util.ResultTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Auther:Liu
 * @Testname:GlobalExceptionHandler
 * @Date:2025/9/19 12:44
 */
@RestControllerAdvice
@Slf4j
//相当一个容器，注册所有的异常
public class GlobalExceptionHandler {

    @ExceptionHandler(CarException.class)
    public JsonResult carException(Throwable e) {
        return ResultTool.fail(515, e.getMessage());
    }
    @ExceptionHandler(PetException.class)
    public JsonResult petException(Throwable e) {
        return ResultTool.fail(516, e.getMessage());
    }
    @ExceptionHandler(BuildingException.class)
    public JsonResult buildingException(Throwable e) {
        return ResultTool.fail(517, e.getMessage());
    }
    @ExceptionHandler(ParkingUseException.class)
    public JsonResult parkingUseException(Throwable e) {
        return ResultTool.fail(525, e.getMessage());
    }

    @ExceptionHandler(ActivityException.class)
    public JsonResult activityException(Throwable e) {
        return ResultTool.fail(518, e.getMessage());
    }
    @ExceptionHandler(ChargeDetailException.class)
    public JsonResult chargeDetailException(Throwable e) {
        return ResultTool.fail(519, e.getMessage());
    }
    @ExceptionHandler(ChargeItemExcception.class)
    public JsonResult chargeItemExcception(Throwable e) {
        return ResultTool.fail(520, e.getMessage());
    }
    @ExceptionHandler(CommunityException.class)
    public JsonResult communityException(Throwable e) {
        return ResultTool.fail(521, e.getMessage());
    }
    @ExceptionHandler(ComplaintException.class)
    public JsonResult complaintException(Throwable e) {
        return ResultTool.fail(522, e.getMessage());
    }
    @ExceptionHandler(DeviceException.class)
    public JsonResult deviceException(Throwable e) {
        return ResultTool.fail(523, e.getMessage());
    }
    @ExceptionHandler(EstateManagerException.class)
    public JsonResult estateManagerException(Throwable e) {
        return ResultTool.fail(524, e.getMessage());
    }

    @ExceptionHandler(ParkingException.class)
    public JsonResult parkingException(Throwable e) {
        return ResultTool.fail(526, e.getMessage());
    }

    @ExceptionHandler(OwnerException.class)
    public JsonResult ownerException(Throwable e) {
        return ResultTool.fail(527, e.getMessage());
    }
    @ExceptionHandler(LetterException.class)
    public JsonResult letterException(Throwable e) {
        return ResultTool.fail(528, e.getMessage());
    }

    @ExceptionHandler(HouseException.class)
    public JsonResult houseException(Throwable e) {
        return ResultTool.fail(529, e.getMessage());
    }
}
